package leetcode.treeCode.week5.leetcode_701;

class Solution {
    public TreeNode insertIntoBST(TreeNode root, int val) {
        return dfs(root,val);
    }
    public TreeNode dfs(TreeNode cur ,int val){
        if (cur == null){
            return new TreeNode(val);
        }
        if (cur.val>val){
            TreeNode node = dfs(cur.left, val);
            cur.left = node;
        }
        else if (cur.val<val){
            TreeNode node = dfs(cur.right, val);
            cur.right = node;
        }
        return cur;
    }
}